package com.ucs.restlet.firstres;

import java.io.IOException;

import org.restlet.representation.InputRepresentation;
import org.restlet.representation.Representation;
import org.restlet.representation.StringRepresentation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.ResourceException;

public class FirstResourceClientMain {
	 public static void get(ClientResource clientResource) throws IOException,ResourceException {   
		 clientResource.get();   
		 if (clientResource.getStatus().isSuccess() && clientResource.getResponseEntity().isAvailable()) {   
			 clientResource.getResponseEntity().write(System.out);   
		 } 
	 } 
	
	public static void main(String[] args) throws Exception{
		ClientResource itemsRc = new ClientResource("http://localhost:8182/items");
		
		Item item = new Item("item1", "this is an item."); 
		Representation r = itemsRc.post(new StringRepresentation(XStremUtil.toXML(item))); 
		System.out.println("posted item");
//        if (itemsRc.getStatus().isSuccess()) {   
//        	ClientResource  itemResource = new ClientResource(r.getIdentifier());   
//	        if (itemResource != null) {   
//	            // Prints the representation of the newly created resource.   
//	            get(itemResource);   
//	  
//	            // Prints the list of registered items.   
//	            get(itemsRc);   
//	  
//	            // Update the item   
//	            item.setDescription("This is an other description");   
//	            itemResource.put(new StringRepresentation(XStremUtil.toXML(item)));   
//	  
//	            // Prints the list of registered items.   
//	            get(itemsRc);   
//	  
//	            // delete the item   
//	            itemResource.delete();   
//	  
//	            // Print the list of registered items.   
//	            get(itemsRc);   
//	        }   
//	    }   
	}

}
